package com.itheima.controller;

import com.itheima.pojo.PePermissionGroup;
import com.itheima.service.PermissionGroupService;
import com.itheima.util.PageResult;
import com.itheima.util.PesGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permissions")
public class PermissionsController {
    @Autowired
    private PermissionGroupService permissionGroupService;

    //权限组列表
    @GetMapping
    public PageResult findPage(Integer page,Integer pagesize,String title){
        return permissionGroupService.findPage(page,pagesize,title);
    }

    //权限组删除
    @DeleteMapping("/{id}")
    public void del(@PathVariable Integer id){
        permissionGroupService.del(id);
    }

    //权限组添加
    @PostMapping
    public void add(@RequestBody PesGroup pesGroup){
        permissionGroupService.add(pesGroup);
    }

    //权限组简单列表
    @GetMapping("/simple")
    public List sim(String title){
        return permissionGroupService.sim(title);
    }

    //权限组修改
    @PutMapping("/{id}")
    public void updateById(@PathVariable Integer id,@RequestBody PesGroup pesGroup){
        permissionGroupService.updateById(id,pesGroup);
    }

    //权限组详情
    @GetMapping("/{id}")
    public PePermissionGroup detail(@PathVariable Integer id){
        return permissionGroupService.detail(id);
    }
}
